package com.ruoyi.event.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.event.domain.bo.EventGkcsBo;
import com.ruoyi.event.domain.vo.EventGkcsVo;
import com.ruoyi.event.service.IEventGkcsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 管控措施
 *
 * @author strongme
 * @date 2023-02-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/event/gkcs")
public class EventGkcsController extends BaseController {

    private final IEventGkcsService iEventGkcsService;

    /**
     * 查询管控措施列表
     */
    @GetMapping("/list")
    public TableDataInfo<EventGkcsVo> list(EventGkcsBo bo, PageQuery pageQuery) {
        return iEventGkcsService.queryPageList(bo, pageQuery);
    }

    @PostMapping("query")
    public R<List<EventGkcsVo>> query(@RequestBody EventGkcsBo bo) {
        return R.ok(iEventGkcsService.queryList(bo));
    }

    /**
     * 导出管控措施列表
     */
    @Log(title = "管控措施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EventGkcsBo bo, HttpServletResponse response) {
        List<EventGkcsVo> list = iEventGkcsService.queryList(bo);
        ExcelUtil.exportExcel(list, "管控措施", EventGkcsVo.class, response);
    }

    /**
     * 获取管控措施详细信息
     *
     * @param gkcsId 主键
     */
    @GetMapping("/{gkcsId}")
    public R<EventGkcsVo> getInfo(@NotNull(message = "主键不能为空")
                                  @PathVariable Long gkcsId) {
        return R.ok(iEventGkcsService.queryById(gkcsId));
    }

    /**
     * 新增管控措施
     */
    @Log(title = "管控措施", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EventGkcsBo bo) {
        return toAjax(iEventGkcsService.insertByBo(bo));
    }

    /**
     * 修改管控措施
     */
    @Log(title = "管控措施", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EventGkcsBo bo) {
        return toAjax(iEventGkcsService.updateByBo(bo));
    }

    /**
     * 删除管控措施
     *
     * @param gkcsIds 主键串
     */
    @Log(title = "管控措施", businessType = BusinessType.DELETE)
    @DeleteMapping("/{gkcsIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] gkcsIds) {
        return toAjax(iEventGkcsService.deleteWithValidByIds(Arrays.asList(gkcsIds), true));
    }
}
